<!--
 * @Descripttion: 熊大写的
 * @version: 1.0.0
 * @Author: xt_xiong
 * @Date: 2022-01-18 18:05:17
 * @LastEditors: xt_xiong
 * @LastEditTime: 2022-01-20 11:27:29
-->
<template>
  <div>
    <el-form el-form ref="Subject" :model="Subject" :rules="rules">
      <el-form-item prop="Subject.subjectName" label="学科名称">
        <el-input
          type="text"
          v-model="Subject.subjectName"
          style="width: 240px"
          placeholder="请输入学科名称"
          >{ row }</el-input
        >
      </el-form-item>
      <el-form-item label="是否显示">
        <el-switch
          :active-value="1"
          :inactive-value="0"
          v-model="Subject.isFrontDisplay"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-form-item>
      <el-form-item style="margin-left: 240px">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { add, update } from '@/api/hmmm/subjects.js'
export default {
  name: '',
  props: {
    pid: {
      type: String,
      default: ''
    },
    visible: {
      type: Boolean
    },
    isEdit: {
      type: Boolean
    },
    row: {
      type: Object
    }
  },
  // watch: {
  //   isEdit: {
  //     handler (newVal) {
  //       console.log('23232', newVal)
  //       if (newVal) {
  //         this.Subject = JSON.parse(JSON.stringify(this.row))
  //         this.Subject = newVal
  //       }
  //     },
  //     immutable: true
  //   }
  // },
  data () {
    return {
      value: true,
      Subject: {
        subjectName: '',
        isFrontDisplay: false
      },
      rules: {
        subjectName: [
          { required: true, message: '学科名不能为空', trigger: 'blur' },
          { min: 1, max: 4, message: '学科名为1-4位', trigger: 'blur' }
        ]
      }
    }
  },
  created () {},

  mounted () {},

  methods: {
    // 学科信息回显(学科修改) ajax
    async editSubMes () {
      await update(this.Subject)
      this.$emit('getSubMes')
    },

    // 提交学科信息的ajax
    async submit () {
      this.$refs.Subject.validate((valid) => {
        if (valid) {
          this.isEdit ? this.editSubMes() : this.toAdd()
        }
      })
      // console.log(res.data, '添加成功!')
      this.closeHandler()
    },
    async toAdd () {
      const res = await add(this.Subject)
      console.log(res)
    },
    closeHandler () {
      this.$emit('close')
      // this.$emit('update:visible', false)
    },
    cancel () {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
el-input:focus::-webkit-input-placeholder {
  color: transparent;
}
/* Mozilla Firefox 4 to 18 */

el-input:focus:-moz-placeholder {
  color: transparent;
}

/* Mozilla Firefox 19+ */

el-input:focus::-moz-placeholder {
  color: transparent;
}

/* Internet Explorer 10+ */

el-input:focus:-ms-input-placeholder {
  color: transparent;
}
</style>
